import 'package:boss/provider/material_provider.dart';
import 'package:boss/ui/page/commodity/material/page/materialDetail/provider/material_detail_provider.dart';
import 'package:boss/ui/widget/button/fixed_bottom_btn.dart';
import 'package:boss/ui/widget/button/fixed_bottom_double_btn.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class MaterialDetailFooter extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Consumer<MaterialDetailProvider>(
      builder: (context, materialDetailProvider, _) {
        return materialDetailProvider.isEditForDetailPage
            ? FixedBottomDoubleBtn(
                onFirst: () async {
                  var materialProvider = Provider.of<MaterialProvider>(
                    context,
                    listen: false,
                  );
                  materialProvider.updateMaterial(materialDetailProvider.data);
                },
                onSecond: () async {
                  var materialProvider = Provider.of<MaterialProvider>(
                    context,
                    listen: false,
                  );
                  materialProvider.deleteMaterialById(materialDetailProvider.data.id);
                },
              )
            : FixedBottomBtn(
                title: '保存',
                onTap: () async {
                  var materialProvider = Provider.of<MaterialProvider>(
                    context,
                    listen: false,
                  );
                  materialProvider.addMaterial(materialDetailProvider.data);
                },
              );
      },
    );
  }
}
